Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

314
Vistas
Getting Javascript error: "Uncaught TypeError: document.getElementById(...) is null"

I've been scratching my head for a while now, I'm a novice with Javascript, but this is a first for me. Here is some very simple html and javascript code that's causing the error in the title:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script>
        document.getElementById("game-column").innerHTML = "test";
    </script>
</head>

<body>
    <div id="game-container">
        <div id="card-column" name="card-column"></div>
        <div id="game-column" name="game-column"></div>
    </div>
</body>
</html>

I'm mainly using firefox for testing.

For some reason it's complaining in the console when I refresh the webpage, however when I run the JS command in the console it seems to work fine. See image below.

Thanks for any responses.

enter image description here

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

This is probably happening because your DOM isn't loaded before your JavaScript is executed. See here for an explanation and solution: https://javascript.info/onload-ondomcontentloaded. Alternatively, you could move your javascript to below your HTML!

about 4 years ago · Juan Pablo Isaza Denunciar

0

add the script to the bottom instead:

like this:

<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>

  <body>
    <div id="game-container">
      <div id="card-column" name="card-column"></div>
      <div id="game-column" name="game-column"></div>
    </div>
    <script>
      document.getElementById("game-column").innerHTML = "test";
    </script>
  </body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda